package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250703094723CreateSysOperateLogTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250703094723CreateSysOperateLogTable) Signature() string {
	return "20250703094723_create_sys_operate_log_table"
}

// Up Run the migrations.
func (r *M20250703094723CreateSysOperateLogTable) Up() error {
	if !facades.Schema().HasTable("sys_operate_log") {
		return facades.Schema().Create("sys_operate_log", func(table schema.Blueprint) {
			table.ID()
			table.Integer("user_id").Comment("用户ID")
			table.String("request_method").Comment("request方法")
			table.String("url").Comment("地址")
			table.String("extra").Comment("扩展字段")
			table.SmallInteger("success").Comment("操作结果")
			table.String("ip").Comment("IP地址")
			table.String("user_agent").Comment("浏览器UA")
			table.TimestampsTz()

			table.Index("url")
			table.Index("user_id")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250703094723CreateSysOperateLogTable) Down() error {
	return facades.Schema().DropIfExists("sys_operate_log")
}
